import { request, type ApiResponse } from './request'




// 创建奖学金请求
export interface CreateScholarshipRequest {
    "studentNum": string,
    "name": string,
    "ranking": number,
    "type": number,
    "gpa": number,
    "applyYear": string,
    "practice": string,
    "awards": string,
    "reason": string
}



/**
 * 获取奖学金列表
 * @param params 查询参数
 * @returns Promise<ApiResponse<ScholarshipListResponse[]>>
 */
export const getScholarshipList = async (): Promise<ApiResponse<any[]>> => {
  return await request<any[]>('scholarship?studentNum=', {
    method: 'GET',
  })
}

/**
 * 根据学号查询学生个人奖学金（path 参数）
 * @param studentNum 学号（作为路径参数，如 /scholarship?studentNum=2）
 * @returns Promise<ApiResponse<ScholarshipListResponse[]>>
 */
export const getScholarshipListByStudentNum = async (
  studentNum: string | number
): Promise<ApiResponse<any[]>> => {
  return await request<any[]>(`scholarship?studentNum=${studentNum}`, {
    method: 'GET',
  })
}

/**
 * 查询待审核、审核中的奖学金
 * @param params 查询参数
 * @returns Promise<ApiResponse<ScholarshipListResponse[]>>
 */
export const getCheckScholarships = async (): Promise<ApiResponse<any[]>> => {
  return await request<any[]>('scholarship/check', {
    method: 'GET',
  })
}

/**
 * 查询审核通过、驳回的奖学金
 * @param params 查询参数
 * @returns Promise<ApiResponse<ScholarshipListResponse[]>>
 */
export const getCheckedScholarships = async (): Promise<ApiResponse<any[]>> => {
  return await request<any[]>('scholarship/checked', {
    method: 'GET',
  })
}

/**
 * 根据奖学金ID查询奖学金详情
 * @param id 奖学金ID
 * @returns Promise<ApiResponse<ScholarshipListResponse[]>>
 */
export const getScholarshipsByScholarshipId = async (id: number | string): Promise<ApiResponse<any[]>> => {
  // 路径参数同样统一转为字符串以避免长整型精度问题
  const normalized = typeof id === 'number' ? String(id) : id
  return await request<any[]>(`scholarship/${normalized}`, {
    method: 'GET',
  })
}

/**
 * 创建奖学金
 * @param data 奖学金信息
 * @returns Promise<ApiResponse<Scholarship>>
 */
export const createScholarship = async (data: CreateScholarshipRequest): Promise<ApiResponse<any>> => {
  return await request<any>('scholarship/add', {  
    method: 'POST',
    body: data
  })
}

/**
 * 批量或者单个奖学金通过
 * @param data 奖学金信息
 * @returns Promise<ApiResponse<string>>
 */
export const updateScholarship = async (data: Array<number | string>): Promise<ApiResponse<string>> => {
  // 将可能超出 JS 安全整数范围的 ID 转为字符串，避免精度丢失
  const normalized = (data || []).map(id => typeof id === 'number' ? String(id) : id)
  return await request<string>('scholarship/pass', {
    method: 'PUT',
    body: normalized
  })
}

// 驳回批量或者单个奖学金
export const rejectScholarship = async (data: Array<number | string>): Promise<ApiResponse<string>> => {
  // 将可能超出 JS 安全整数范围的 ID 转为字符串，避免精度丢失
  const normalized = (data || []).map(id => typeof id === 'number' ? String(id) : id)
  return await request<string>('scholarship/reject', {
    method: 'PUT',
    body: normalized
  })
}
